const { STS } = require('ali-oss');
const ali_config = require('../../config/index.js').ali_oos
const baseComponent = require('../../prototype/baseComponent')
class Oss extends baseComponent {
  constructor() {
    super()
  }
  getAliToken = async (req, res)=> {
    try {
      let sts = new STS({
        accessKeyId: ali_config.accessKeyId,
        accessKeySecret: ali_config.accessKeySecret
      });
      let result = await sts.assumeRole(`acs:ram::${ali_config.ram}:role/${ali_config.role}`)
      let data = {
        AccessKeyId: result.credentials.AccessKeyId,
        AccessKeySecret: result.credentials.AccessKeySecret,
        SecurityToken: result.credentials.SecurityToken,
        Expiration: result.credentials.Expiration,
        region: ali_config.region,
        bucket: ali_config.bucket,
      }
      this.sendSuccess(res, data, '查询成功')
    } catch (error) {
      this.sendError(res,error)
    }
  }
}
module.exports = new Oss()    